#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <stdio.h>
#include "processCircle.h"


int Circle(std::string str, std::string mas[], int i) {
    if((mas[0].substr(0, 7) == "circle(") && mas[0].back() == char(41)){
        mas[0].erase(0, 7);
        reverse(mas[0].begin(), mas[0].end());
        mas[0].erase(0, 1);
        reverse(mas[0].begin(), mas[0].end());
        
        int check = 0;
        int size = mas[0].size();
        for(int i = 0; i < size; i++){
            if(mas[0][i] == char(32) || mas[0][i] == char(44) || mas[0][i] == char(46) || (mas[0][i] >= char(48) && mas[0][i] <= char(57))){
                check++;
            }
        }
        
        if(check == size){
            std::stringstream ss(mas[0]);
            bool flag = false;
            for (int i = 0; mas[0][i] != ',' && mas[0][i] != ' ' && mas[0][i] != '.'; ++i) {
                if (mas[0][i] >= 57 || mas[0][i] <= 47) {
                    flag = true;
                }
            }
            if (flag) {
                return 0;
            }
            
            float num_x, num_y, num_r;
            char comma;
            ss >> num_x >> std::ws >> num_y >> comma >> num_r;
            if (num_r == 0){
                std::stringstream ll(mas[0]);
                ll >> num_x >> comma >> num_y >> comma >> num_r;
            }
            std::cout << "x: " << num_x << ", y: " << num_y << ", r: " << num_r << std::endl;
            std::cout << "square = " << 3.14 * num_r * num_r << std::endl;
            std::cout << "circumference length = " << 3.14 * num_r * 2 << std::endl;
            return 1; 
        } else {
            std::cout << "ERROR" << std::endl;
            return 0;
        }
    } else {
        std::cout << "ERROR" << std::endl;
        return 0;
    }
}

